<template>
	<view class="container">
		<form @submit="submit">
			<image src="/static/imgs/login.png" class="login_back"></image>
			<view class="login_content">
				<view>
					<text class="input_text">手机号</text>
					<input type="number" placeholder="请输入你的手机号码" name="username" />
				</view>
				<view>
					<text class="input_text">密码</text>
					<input type="password" placeholder="请输入密码" name="password" />
				</view>
			</view>
			<view class="uni-btn-v">
				<button form-type="submit">登录</button>
			</view>
		</form>
	</view>
</template>

<script>
	var app = getApp();
	import http from '../../../common/js/request.js';
	import common from '../../../common/js/function.js';
	export default {
		data() {
			return {

			}
		},
		onShow() {
			
		},
		methods: {
			verify(formData) {
				if (!formData.username) {
					uni.showToast({
						title: '手机号不能为空~',
						icon: 'none'
					});
					return false;
				} else if (!formData.password) {
					uni.showToast({
						title: '密码不能为空~',
						icon: 'none'
					});
					return false;
				}
				return true;
			},
			submit(e) {
				var that = this;
				var formData = e.detail.value;
				if (!that.verify(formData)) return;
				http.post('api/store/login/login', {
					...formData,
					openid: wx.getStorageSync('openid') || '',
				}, res => {
					if (res.state == 1) {
						uni.setStorageSync('storeId', res.datas.store_id);
						uni.setStorageSync('authType', res.datas.type);
						uni.navigateTo({
							url: '/pages/merchant/home/home'
						});
					} else {
						uni.showToast({
							title: res.datas,
							icon: 'none'
						});
					}
				});
			}
		}
	}
</script>

<style>
	.login_back {
		width: 100%;
		height: 424rpx;
	}

	.input_text {
		height: 44rpx;
		line-height: 44rpx;
		display: block;
		font-size: 28rpx;
		color: #323232;
	}

	.login_content {
		width: 600rpx;
		margin: 43rpx auto 0;
	}

	.login_content view {
		margin-top: 34rpx;
	}

	.login_content input {
		width: 100%;
		height: 85rpx;
		border-bottom: 1rpx solid #BFBFBF;
		font-size: 28rpx;
	}

	.uni-btn-v button {
		width: 600rpx;
		height: 72rpx;
		line-height: 72rpx;
		background: rgba(255, 157, 17, 1);
		border-radius: 36rpx;
		color: #fff;
		font-size: 30rpx;
		margin-top: 124rpx;
	}
</style>
